//
//  MVVMTableViewController.m
//  iOSCodeLearning
//
//  Created by TFAppleWork-Summer on 2018/4/13.
//  Copyright © 2018年 Ace. All rights reserved.
//

#import "MVVMTableViewController.h"
#import "TableViewViewModel.h"
#import "TableViewCell.h"


@interface MVVMTableViewController ()
@property (nonatomic, strong) TableViewViewModel *viewModel;
@end

@implementation MVVMTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 1 通过viewModel 获取数据
    [self.viewModel getListData:^{
        [self.tableView reloadData];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return [self.viewModel numberOfSection];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [self.viewModel numberOfCell];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TableViewCell *cell = [TableViewCell createCellWithTableView:tableView];
    cell.viewModel = [self.viewModel modelOfIndexPath:indexPath];
    return cell;
}

-(TableViewViewModel *)viewModel{
    if (!_viewModel) {
        _viewModel = [[TableViewViewModel alloc]init];
        _viewModel.queue = dispatch_queue_create("11", DISPATCH_QUEUE_SERIAL);
        _viewModel.actionHandler = ^(NSInteger actionType) {
            switch (actionType) {
                case 0:
                {
                    [SVProgressHUD showSuccessWithStatus:@"点击了跳转"];
                }
                    break;
                    
                default:
                    break;
            }        };
    }
    return _viewModel;
}


-(void)dealloc{
    NSLog(@"-----%@--------",NSStringFromClass([self class]));
}

@end
